package com.jc.order.service.impl;

import com.jc.order.domain.KjbCountry;
import com.jc.order.dto.CountryDTO;
import com.jc.order.mapper.KjbCountryMapper;
import com.jc.order.service.CountryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

@Service
public class CountryServiceImpl implements CountryService {

    @Resource
    private KjbCountryMapper countryMapper;


    @Override
    public CountryDTO selectByCode(String code) {
        Example example = new Example(KjbCountry.class,Boolean.TRUE,Boolean.TRUE);
        example.createCriteria().andEqualTo("countryCode", code).orEqualTo("countryShortCode", code);
        KjbCountry country = countryMapper.selectOneByExample(example);
        if (country == null) {
            return null;
        }
        CountryDTO countryDTO = new CountryDTO();
        BeanUtils.copyProperties(country, countryDTO);
        return countryDTO;
    }
}
